<template>
    <div>
      <el-dialog v-bind="$attrs" v-on="$listeners"
                 @close="onClose"
                 :title="isEdit ? (isSelf ? '房屋信息-编辑' : '投诉房屋') : '投诉意见'" :visible.sync="showDialog"
                 :close-on-click-modal="false">
          <el-form ref="HouseInfoForm" :model="formData" size="small" label-width="98px">
              <el-form-item label="投诉反馈" prop="noticeMessage">
                <el-input size="mini" type="textarea" v-model="formData.errorInfo"></el-input>
              </el-form-item>
          </el-form>
        <div slot="footer">
          <el-button @click="onClose" type="danger" icon="el-icon-close" size="small">取 消</el-button>
          <el-button @click="handelConfirm" type="success" icon="el-icon-upload2" size="small" :disabled="isSubmit">提 交</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
  import { updateStatusFail} from '@/api/houseInfo'
  import { updateComplaint } from '@/api/complaint'
  export default {
    name: 'complaintErrorInfo',
    data () {
      // 数据
      return {
        formData: {
          errorInfo: ''
        },
        rules: {
          errorInfo: [{
            required: true,
            message: '请输入下架原因',
            trigger: 'blur'
          }]
        },
        showDialog: false,
        isSubmit: false,
      }
    },
    props: {
      complaintErrorInfo: {
        type: Boolean,
        default: false
      },
      id: {
        type: Number,
        default: 0
      },
      comId: {
        type: Number,
        default: 0
      },
      isEdit: {
        type: Boolean,
        default: false
      },
      isSelf: {
        type: Boolean,
        default: false
      }
    },
    computed: {},
    watch: {
      // 监听 addOrUpdateVisible 改变
      complaintErrorInfo () {
        this.showDialog = this.complaintErrorInfo
      }
    },
    methods: {
      onClose () {
        // 清除 rule 数据
        this.$emit('changeShow', 'false')
      },
      handelConfirm () {
          const _this = this
          _this.isSubmit = true
          updateComplaint(this.comId).then(response => {
            if(response.code==200){
              updateStatusFail(_this.formData, _this.id).then(response => {
                // 如果是当前登录用户，需要更新 sessionStorage 的数据
                window.sessionStorage.setItem('account', JSON.stringify(_this.formData))
                _this.RightMessage(_this, '投诉成功', response.message + '，请刷新页面！', 'success')
                _this.$emit('update:visible', false)
                _this.$emit('changeShow', 'false')
                _this.$emit('dataUpdate')
              }).finally(() => {
                _this.isSubmit = false
              })
            }else {
              alert(response.message)
            }
          })

      },
      resetFormData () {
        this.formData.errorInfo = undefined
      }
    }
  }
</script>

<style scoped>

</style>
